package com.example.demotest.pojo.dto;

import com.example.demotest.pojo.Product;
import com.example.demotest.pojo.ProductCheckStatus;
import com.example.demotest.pojo.ProductSoldStatus;
import jakarta.validation.constraints.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

public class ProductRequestDto {

    private Integer productId;

    @NotBlank(message = "商品名不能为空")
    private String productName;

    @NotBlank(message = "商品描述不能为空")
    private String description;

    @NotNull(message = "商品价格不能为空")
    @DecimalMin(value = "0.01", message = "价格必须大于0")
    private Double price;

    @NotNull(message = "分类ID不能为空")
    private Integer categoryId;

    private List<String> images;

    private LocalDateTime createdAt;

    private ProductSoldStatus statusSold;

    private ProductCheckStatus statusCheck;

    private Integer userId;

    public ProductRequestDto() {
        // 默认构造方法
    }

    public ProductRequestDto(Product product) {
        this.productId = product.getProductID();
        this.productName = product.getProductName();
        this.description = product.getProductDescription();
        this.price = product.getProductPrice();
        this.categoryId = product.getProductCategory() != null ? product.getProductCategory().getId() : null;;
        this.createdAt = product.getCreatedAt();
        this.statusSold = product.getStatusSold();
        this.statusCheck = product.getStatusCheck();
        this.userId = product.getUserId();
        this.images = product.getImages() != null ? Arrays.asList(product.getImages().split(",")) : null;
    }

    // Getters and Setters
    public Integer getProductId() {
        return productId;
    }

    public void setProductId(Integer productId) {
        this.productId = productId;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Integer getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    public List<String> getImages() {
        return images;
    }

    public void setImages(List<String> images) {
        this.images = images;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public ProductSoldStatus getStatusSold() {
        return statusSold;
    }

    public void setStatusSold(ProductSoldStatus statusSold) {
        this.statusSold = statusSold;
    }

    public ProductCheckStatus getStatusCheck() {
        return statusCheck;
    }

    public void setStatusCheck(ProductCheckStatus statusCheck) {
        this.statusCheck = statusCheck;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    @Override
    public String toString() {
        return "ProductRequestDto{" +
                "productId=" + productId +
                ", productName='" + productName + '\'' +
                ", description='" + description + '\'' +
                ", price=" + price +
                ", categoryId=" + categoryId +
                ", images=" + images +
                ", createdAt=" + createdAt +
                ", statusSold=" + statusSold +
                ", statusCheck=" + statusCheck +
                ", userId=" + userId +
                '}';
    }

}
